//
//  HomeGraphTopCell.m
//  iphone-graph
//
//  Created by yuzhuo on 2016/12/27.
//  Copyright © 2016年 yzapp. All rights reserved.
//

#import "HomeGraphTopCell.h"
#import "Constant.h"
#import "UIColor+Util.h"
#import "TopTableViewCell.h"
#import "ImageViewController.h"

@interface HomeGraphTopCell ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation HomeGraphTopCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if(self){
        [self initSubViews];
        self.accessoryType = UITableViewCellAccessoryNone;//
    }
    return self;
}


-(void) initSubViews
{
    self.backgroundColor = [UIColor whiteColor];
    
    
    self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 140, self.frame.size.width)];
    
//    [self.tabView.layer setAnchorPoint:CGPointMake(0.0, 0.0)];
    
    self.tabView.transform = CGAffineTransformMakeRotation(-M_PI_2);
    
    self.tabView.dataSource = self;
    
    self.tabView.delegate  = self;
    
    self.tabView.scrollEnabled = YES;
    
    self.tabView.userInteractionEnabled = YES;
    
    //    myTableView.showsHorizontalScrollIndicator = NO;
    
    self.tabView.showsVerticalScrollIndicator = NO;
    
    self.tabView.frame = CGRectMake(15, 0, SCREEN_WIDTH-30, 140);
    
    self.tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tabView setBackgroundColor:[UIColor whiteColor]];
    
    [self.contentView addSubview:self.tabView];

}



-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"cellID";
    TopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(cell == nil){
        cell = [[TopTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if(indexPath.row < self.data.count){
        cell.data = self.data[indexPath.row];
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    ImageViewController *detailview = [ImageViewController new];
    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           
           object != nil) {
        
        object = [object nextResponder];
        
    }
    UIViewController *uc=(UIViewController*)object;
    [uc.navigationController pushViewController:detailview animated:YES];
    NSLog(@"click row%ld",indexPath.row);
    
}



#pragma mark -SetData

-(void)setData:(NSArray<UIImage *> *)data
{
    _data = data;
    
}


@end
